/* 明亮主题和暗黑主题变量 */
:root {
    /* 明亮主题 */
    --primary-color: #2563eb;
    --danger-color: #dc2626;
    --background-color: #f8fafc;
    --chat-background: #ffffff;
    --text-color: #1e293b;
    --border-color: #e2e8f0;
    --message-bg-user: #f1f5f9;
    --message-bg-assistant: #ffffff;
    --message-assistant-border: #e2e8f0;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --code-bg: #f3f4f6;
    --code-color: #374151;
    --sidebar-bg: #f1f5f9;
    --sidebar-header: #e2e8f0;
    --action-btn-bg: #f1f5f9;
    --action-btn-color: #64748b;
    --action-btn-hover-bg: #e2e8f0;
    /* 颜色变量 - 浅色模式 */
    --secondary-color: #6c757d;
    --input-bg: #ffffff;
    --muted-text-color: #6c757d;
    --header-bg: #ffffff;
    --message-user-bg: #e9f0f9;
    --message-assistant-bg: #ffffff;
    --hover-color: #f2f2f2;
    --active-item-bg: #e6f0ff;
    --item-bg: #ffffff;
    --system-message-bg: #f8f9fa;
    --notification-bg: #ffeeba;
    --token-count-bg: #e9ecef;
    --token-count-color: #6c757d;
    --danger-light: #f8d7da;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
}

/* 暗黑主题 */
[data-theme="dark"] {
    --primary-color: #3b82f6;
    --danger-color: #ef4444;
    --background-color: #1e293b;
    --chat-background: #0f172a;
    --text-color: #e2e8f0;
    --border-color: #334155;
    --message-bg-user: #1e293b;
    --message-bg-assistant: #0f172a;
    --message-assistant-border: #334155;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --code-bg: #111827;
    --code-color: #e5e7eb;
    --sidebar-bg: #1e293b;
    --sidebar-header: #334155;
    --action-btn-bg: #334155;
    --action-btn-color: #e2e8f0;
    --action-btn-hover-bg: #475569;
    /* 添加CSS变量 - 深色模式 */
    --secondary-color: #adb5bd;
    --input-bg: #343a40;
    --header-bg: #343a40;
    --message-user-bg: #2a4365;
    --message-assistant-bg: #343a40;
    --hover-color: #3a3f44;
    --active-item-bg: #2b3035;
    --item-bg: #343a40;
    --system-message-bg: #2b3035;
    --notification-bg: #856404;
    --token-count-bg: #343a40;
    --token-count-color: #adb5bd;
    --danger-color: #f56565;
    --danger-light: #742a2a;
    --success-color: #48bb78;
    --warning-color: #ecc94b;
    --info-color: #4299e1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.chat-container {
    background-color: var(--chat-background);
    border-radius: 1rem;
    box-shadow: 0 4px 6px var(--shadow-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    transition: background-color 0.3s, box-shadow 0.3s;
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    transition: border-color 0.3s;
}

.chat-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.25rem;
}

.login-button, .theme-toggle-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.3s;
}

/* 退出按钮样式 */
#logout-btn {
    background-color: var(--danger-color);
}

#logout-btn:hover {
    background-color: #b91c1c;
}

.theme-toggle-button {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-button:hover, .theme-toggle-button:hover {
    background-color: #1d4ed8;
}

.token-info {
    font-size: 0.875rem;
    color: #64748b;
    display: flex;
    align-items: center;
    margin-top: 0.25rem;
}

/* Token计数显示 */
#token-count {
    padding: 0.5rem 0.75rem;
    margin-top: 0.5rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    background-color: #f1f5f9;
    color: #1e293b;
    transition: all 0.3s;
    cursor: help;
}

/* Token计数警告状态 */
.token-count-warning {
    background-color: #fef9c3 !important;
    color: #854d0e !important;
}

/* Token计数危险状态 */
.token-count-danger {
    background-color: #fee2e2 !important;
    color: #b91c1c !important;
}

[data-theme="dark"] #token-count {
    background-color: #334155;
    color: #e2e8f0;
}

[data-theme="dark"] .token-count-warning {
    background-color: #78350f !important;
    color: #fef9c3 !important;
}

[data-theme="dark"] .token-count-danger {
    background-color: #7f1d1d !important;
    color: #fee2e2 !important;
}

/* 三栏布局 */
.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* 左侧历史记录 */
.chat-history {
    width: 220px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    font-weight: bold;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--header-bg);
    color: var(--text-color);
}

.clear-history-btn,
.new-chat-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    font-size: 14px;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.clear-history-btn:hover,
.new-chat-btn:hover {
    background-color: var(--hover-color);
}

#conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.history-item {
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 8px;
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s;
    display: flex;
    flex-direction: column;
    background-color: var(--item-bg);
}

.history-item:hover {
    background-color: var(--hover-color);
}

.history-item.active {
    background-color: var(--active-item-bg);
    border-left: 3px solid var(--primary-color);
}

.history-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 12px;
    color: var(--muted-text-color);
}

.history-delete {
    position: absolute;
    right: 5px;
    top: 5px;
    background: none;
    border: none;
    color: var(--muted-text-color);
    cursor: pointer;
    padding: 3px;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
}

.history-item:hover .history-delete {
    opacity: 1;
}

.history-delete:hover {
    background-color: var(--danger-light);
    color: var(--danger-color);
}

.empty-history-message {
    text-align: center;
    padding: 20px;
    color: var(--muted-text-color);
    font-style: italic;
}

/* 系统消息文本样式 */
.system {
    font-style: italic;
    color: var(--muted-text-color);
    text-align: center;
    padding: 5px 15px;
    margin: 10px auto;
    max-width: 90%;
    background-color: var(--system-message-bg);
    border-radius: 15px;
    font-size: 14px;
}

.system.temp-message {
    animation: fadeInOut 2s ease-in-out;
    background-color: var(--notification-bg);
    color: var(--text-color);
}

.token-count-message {
    text-align: center;
    padding: 5px 10px;
    margin: 10px auto;
    max-width: 90%;
    background-color: var(--token-count-bg);
    border-radius: 8px;
    font-size: 12px;
    color: var(--token-count-color);
}

/* 中间主聊天区域 */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* 图片预览容器 */
.image-preview-container {
    display: none;
    position: absolute;
    bottom: 120px;
    left: 50px;
    z-index: 100;
    background-color: var(--chat-background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-color);
    padding: 5px;
    transition: all 0.3s;
}

.image-preview-container.active {
    display: block;
}

.image-preview {
    position: relative;
    max-width: 120px;
    max-height: 120px;
    overflow: hidden;
}

.image-preview::after {
    content: "已上传图片";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 10px;
    padding: 2px 4px;
    text-align: center;
}

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    cursor: pointer;
    border-radius: 4px;
}

.close-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: #ef4444;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px var(--shadow-color);
    z-index: 20;
}

.close-image-btn:hover {
    background-color: #dc2626;
}

/* 文件上传区 */
.file-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.upload-file-btn {
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    color: #64748b;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.upload-file-btn:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.chat-input-container {
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    position: relative;
    transition: border-color 0.3s;
}

.input-controls {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    overflow: hidden;
    background-color: var(--message-user-bg);
    transition: border-color 0.3s, background-color 0.3s;
    align-items: center;  /* 确保子元素垂直居中 */
    position: relative;   /* 使图片图标可以相对于此定位 */
}

.input-tools {
    display: flex;
    gap: 0.25rem;  /* 减小工具间的间距 */
    padding: 0 0.5rem 0 0.75rem;  /* 右侧减小一点，给文本框更多空间 */
    align-items: center;
}

/* 修改上传按钮样式，使其在同一行显示 */
.image-upload-label, .doc-upload-label {
    width: 32px;
    height: 32px;
    background-color: var(--action-btn-bg);
    color: var(--action-btn-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-right: 0.25rem;  /* 减小按钮之间的间距 */
}

.image-upload-label:hover, .doc-upload-label:hover {
    background-color: var(--action-btn-hover-bg);
}

textarea {
    flex: 1;
    border: none;
    padding: 0.75rem 0.5rem;  /* 左右减小一点内边距 */
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-color);
    background-color: transparent;
    outline: none;
    height: 44px;
    max-height: 150px;
    overflow-y: auto;
    transition: color 0.3s;
}

textarea:focus {
    outline: none;
}

button {
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

#send-button {
    min-width: 80px;
    border-radius: 0 0.5rem 0.5rem 0;
}

#stop-button {
    min-width: 80px;
    border-radius: 0 0.5rem 0.5rem 0;
    background-color: #e11d48; /* 红色背景 */
}

#stop-button:hover {
    background-color: #be123c; /* 深红色背景悬停效果 */
}

button:hover {
    background-color: #1d4ed8;
}

button:disabled {
    background-color: #94a3b8;
    cursor: not-allowed;
}

/* 右侧边栏 */
.sidebar {
    width: 200px;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background-color: var(--sidebar-bg);
    transition: background-color 0.3s, border-color 0.3s;
}

.sidebar-header {
    padding: 0.75rem;
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--sidebar-header);
    transition: background-color 0.3s, border-color 0.3s;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.platform-link {
    padding: 0.5rem;
    margin: 0.25rem 0;
    border-radius: 0.25rem;
    transition: background-color 0.2s;
}

.platform-link:hover {
    background-color: var(--border-color);
}

.platform-link a {
    color: var(--text-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.3s;
}

/* 版权信息 */
.copyright {
    text-align: center;
    padding: 0.75rem;
    color: #64748b;
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

/* 消息样式 */
.message {
    margin-bottom: 1.5rem;
    padding: 1.25rem;
    border-radius: 0.75rem;
    max-width: 90%;
    transition: background-color 0.3s, border-color 0.3s;
    box-shadow: 0 1px 3px var(--shadow-color);
}

.message.user {
    background-color: var(--message-user-bg);
    margin-left: auto;
}

.message.assistant {
    background-color: var(--message-assistant-bg);
    border: 1px solid var(--message-assistant-border);
}

.message.system {
    background-color: var(--sidebar-bg);
    color: #6c757d;
    font-style: italic;
    font-size: 0.9rem;
    padding: 0.75rem;
    margin: 0.5rem auto;
    text-align: center;
    max-width: 90%;
    border: 1px dashed var(--border-color);
}

/* 消息内容布局 */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message-text {
    word-break: break-word;
}

/* Token计数显示 */
.token-count-message {
    text-align: center;
    color: #64748b;
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    margin: 0.75rem auto;
    background-color: #f1f5f9;
    border-radius: 0.5rem;
    max-width: 80%;
    border: 1px dashed #cbd5e1;
    position: relative;
}

/* 暗黑模式下的token计数消息 */
[data-theme="dark"] .token-count-message {
    background-color: #334155;
    color: #cbd5e1;
    border-color: #475569;
}

/* 消息中的图片样式 */
.message-image {
    max-width: 100%;
    margin-top: 0.5rem;
    border-radius: 0.25rem;
    max-height: 300px;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

/* 模态图片查看器 */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.image-modal.active {
    display: flex;
}

.modal-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

/* Markdown 样式 */
.message-text h1, 
.message-text h2, 
.message-text h3, 
.message-text h4, 
.message-text h5, 
.message-text h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    line-height: 1.25;
}

.message-text h1 {
    font-size: 1.5rem;
}

.message-text h2 {
    font-size: 1.3rem;
}

.message-text h3 {
    font-size: 1.2rem;
}

.message-text p {
    margin-bottom: 0.75rem;
}

.message-text a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

.message-text ul, 
.message-text ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-text li {
    margin: 0.25rem 0;
}

.message-text blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 1rem;
    color: #64748b;
    margin: 0.5rem 0;
}

.message-text code {
    background-color: var(--code-bg);
    color: var(--code-color);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-family: monospace;
    font-size: 0.9em;
}

.message-text pre {
    background-color: var(--code-bg);
    overflow-x: auto;
    padding: 1rem;
    border-radius: 0.5rem;
    margin: 0.75rem 0;
}

.message-text pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    color: inherit;
}

.code-block {
    position: relative;
}

/* 响应式布局 */
@media (max-width: 1024px) {
    .container {
        padding: 0.5rem;
    }
    
    .app-layout {
        flex-direction: column;
    }
    
    .chat-history, .sidebar {
        width: 100%;
        height: auto;
        max-height: 150px;
    }
    
    .chat-main {
        min-height: 50vh;
    }
}

/* 临时提示消息样式 */
.temp-message {
    background-color: var(--primary-color) !important;
    color: white !important;
    font-weight: 500;
    padding: 0.5rem 1rem;
    margin: 0.5rem auto;
    border-radius: 0.5rem;
    border: none !important;
    max-width: 80%;
    text-align: center;
    animation: fadeInOut 2s ease-in-out;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateY(-10px); }
    15% { opacity: 1; transform: translateY(0); }
    85% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}

[data-theme="dark"] .temp-message {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .image-preview {
    background-color: var(--chat-background);
    border-color: var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .image-preview-container {
        bottom: 130px;
        left: 10px;
    }
    
    .image-preview {
        max-width: 100px;
        max-height: 100px;
    }
}

/* 清除历史按钮样式 */
.clear-history-btn {
    background-color: #4361ee;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 4px 8px;
    margin-left: auto; /* 使按钮靠右对齐 */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.clear-history-btn:hover {
    background-color: #3a56e0;
}

/* 历史记录头部样式，使其变为flex布局 */
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between; /* 在两端分布元素 */
    padding: 10px;
    background-color: var(--secondary-color);
    color: var(--text-color);
    font-weight: bold;
    border-bottom: 1px solid var(--border-color);
} 